package com.tang.controller;

import com.tang.pojo.AnswerQuestion;
import com.tang.pojo.ChoiceQuestion;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class QuestionBackController {

    public String createPaper(String candidate, String number) {
        List<ChoiceQuestion> choiceQuestionList = new ArrayList<>();
        List<AnswerQuestion> answerQuestionList = new ArrayList<>();

        String question01 = "JAVA所定义的版本中不包括";
        Map<String, String> map01 = new HashMap<String, String>() {{
            put("A", "JAVA2 EE");
            put("B", "JAVA2 Card");
            put("C", "JAVA2 ME");
            put("D", "JAVA2 HE");
            put("E", "JAVA2 SE");
        }};
        String key01 = "D";

        String question02 = "下列说法正确的是";
        Map<String, String> map02 = new HashMap<String, String>() {{
            put("A", "JAVA程序的main方法必须写在类里面");
            put("B", "JAVA程序中可以有多个main方法");
            put("C", "JAVA程序中类名必须与文件名一样");
            put("D", "JAVA程序的main方法中如果只有一条语句，可以不同{}（大括号）括起来");
        }};
        String key02 = "A";

        String question03 = "变量命名规范说法正确的是";
        Map<String, String> map03 = new HashMap<String, String>() {{
            put("A", "变量由字母、下划线、数字、$符号随意组成");
            put("B", "变量不能以数字作为开头");
            put("C", "A和a在java中是同一个变量");
            put("D", "不同类型的变量，可以起相同的名字");
        }};
        String key03 = "B";

        String question04 = "以下()不是合法的标识符";
        Map<String, String> map04 = new HashMap<String, String>() {{
            put("A", "STRING");
            put("B", "x3x");
            put("C", "void");
            put("D", "de$f");
        }};
        String key04 = "C";

        String question05 = "表达式(11+3*8)/4%3的值是";
        Map<String, String> map05 = new HashMap<String, String>() {{
            put("A", "31");
            put("B", "0");
            put("C", "1");
            put("D", "2");
        }};
        String key05 = "D";

        choiceQuestionList.add(new ChoiceQuestion(question01, map01, key01));
        choiceQuestionList.add(new ChoiceQuestion(question02, map02, key02));
        choiceQuestionList.add(new ChoiceQuestion(question03, map03, key03));
        choiceQuestionList.add(new ChoiceQuestion(question04, map04, key04));
        choiceQuestionList.add(new ChoiceQuestion(question05, map05, key05));
        answerQuestionList.add(new AnswerQuestion("小红马和小黑马生的小马几条腿", "4条腿"));
        answerQuestionList.add(new AnswerQuestion("铁棒打头疼还是木棒打头疼", "头最疼"));
        answerQuestionList.add(new AnswerQuestion("什么床不能睡觉", "牙床"));
        answerQuestionList.add(new AnswerQuestion("为什么好马不吃回头草", "后面的草没了"));

        StringBuilder detail = new StringBuilder("考生：");
        detail.append(candidate);
        detail.append("\r\n考号：");
        detail.append(number);
        detail.append("\r\n------------------------------------------------------\r\n");
        detail.append("一、选择题\r\n\n");
        int size = choiceQuestionList.size();
        for (int idx = 0; idx < size; idx++) {
            detail.append("第").append(idx + 1).append("题").append(choiceQuestionList.get(idx).getName())
                    .append("\r\n");
            Map<String, String> option = choiceQuestionList.get(idx).getOption();
            for (Map.Entry<String, String> entry : option.entrySet()) {
                detail.append(entry.getKey()).append("：").append(entry.getValue()).append("\r\n");
            }
            detail.append("答案：").append(choiceQuestionList.get(idx).getKey()).append("\r\n\n");
        }

        detail.append("二、问答题\r\n\n");

        for (int i = 0; i < answerQuestionList.size(); i++) {
            detail.append("第").append(i + 1).append("题：").append(answerQuestionList.get(i).getName()).append("\r\n");
            detail.append("答案：").append(answerQuestionList.get(i).getKey()).append("\r\n\n");
        }

        return detail.toString();
    }


}
